function validate(id, type, message, min, max) {
	var display_message = false;
	var value = $("#" + id).val();
	
	// No point in trying to validate if we don't have any text!
	if (value) {
		
		// Minimum length validation
		if (min && (value.length < min)) 
			display_message = 'Must be ' + min + ' characters or more';
		
		// Maximum length validation
		if (max && (value.length > max)) 
			display_message = 'Must be ' + max + ' characters or less';		
		
		// Alphanumeric Validation
		if (type == "alnum") {
			if (!message) message = 'Must contain no invalid characters'
			if (value.match(/([^a-zA-Z0-9/._-])/)) display_message = message;
		}			
		
		// Alpha Validation
		if (type == "alpha") {
			if (!message) message = 'Must contain no numbers or invalid characters'
			if (value.match(/([^a-zA-Z/._-])/)) display_message = message;
		}

		// Number Validaiton
		if (type == "num") {
			if (!message) message = 'Must be a number'
			if (value.match(/\D+/)) display_message = message;
		}
		
		// Email Validation
		if (type == "email") {
			if (!message) message = 'Must be a valid email address'
			if (!value.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) display_message = message;
		}	
		
		// Update the element
		if (display_message) {
			$(submit).attr("disabled", "true");
			$("#feedback_" + id).html(display_message).fadeIn("slow");
		}
			
	}

	if (!value || !display_message) {
		$(submit).removeAttr('disabled'); 
		$("#feedback_" + id).fadeOut("slow");
	}

}

function required(id) {
	var value = $("#" + id).val();
	if (!value) {
		$("#feedback_" + id).hide().html('Please fill in this field').fadeIn("slow");
		$(submit).attr("disabled", "true");
	} else $(submit).removeAttr('disabled'); 
}

function password_strength(id, password) {

	var description = new Array();
	description[0] = "<div style=\"color:#676767\"><b>Too Short</b></div>";
	description[1] = "<div style=\"color:#AA0033\"><b>Weak</b></div>";
	description[2] = "<div style=\"color:#FFCC33\"><b>Fair</b></div>";
	description[3] = "<div style=\"color:#6699CC\"><b>Good</b></div>";	
	description[4] = "<div style=\"color:#008000\"><b>Strong</b></div>";
	var score = 0;

	// Output the needed CSS on first call
	if (!$("#password_description_" + id)) {
		document.write("<style type=\"text/css\">");
		document.write("#password_description_" + id + " { display:block; float:left; }");
		document.write("#password_strength_box { clear:both; width:150px; display:block; background:#E0E0E0;  }");		
		document.write("#password_strength_" + id + " { height:5px; }");
		document.write(".password_strength_0 { height:5px; width:150px; background:#E0E0E0; }");
		document.write(".password_strength_1 { height:5px; width:25px; background:#AA0033; }");
		document.write(".password_strength_2 { height:5px; width:50px; background:#FFCC33; }");
		document.write(".password_strength_3 { height:5px; width:125px; background:#6699CC; }");
		document.write(".password_strength_4 { height:5px; width:150px; background:#008000; }");
		document.write("</style>");
	}
	// Otherwise process the password
	else {
		// If password has both lower and uppercase letters
		if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;
	
		// If password has a number
		if (password.match(/\d+/)) score++;
	
		// If password has a special character
		if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
		
		// If password length is eight letters or more
		if (password.length > 7) score++;
		else score = 0;
		
		// Update the elements
		$("#password_description_" + id).html(description[score]);
		$("#password_strength_" + id).attr("class", "password_strength_" + score);
	}
}